package com.linx.common.web.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.linx.common.core.utils.SpringUtils;
import com.linx.common.web.domain.bo.CardBindingsRequest;
import com.linx.common.web.domain.bo.FaceSingleAddRequest;
import com.linx.common.web.domain.bo.FaceSingleUpdateRequest;
import com.linx.common.web.domain.vo.CardBindingsVo;
import com.linx.common.web.domain.vo.FaceSingleAddVo;
import com.linx.common.web.domain.vo.FaceSingleUpdateVo;
import com.linx.common.web.domain.vo.ResponseVo;
import com.linx.common.web.properties.HkProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/***
 * @ClassName FaceSingleControlUtils
 * @Description 批量开卡控制工具类
 * @Author gushaoliang
 * @Date 2024/12/4 下午6:34
 * @Version 1.0
 */
@Component
@Slf4j
public class CarBindingsControlUtils {

    private String agreement;
    private String host;
    private String appKey;
    private String appSecret;
    private String artemisPath;


    public CarBindingsControlUtils() {
        HkProperties hkProperties = SpringUtils.getBean(HkProperties.class);
        agreement = hkProperties.getAgreement();
        host = hkProperties.getHost();
        appKey = hkProperties.getAppKey();
        appSecret = hkProperties.getAppSecret();
        artemisPath = hkProperties.getArtemisPath();
    }

    //批量开卡
    public ResponseVo  bindings(CardBindingsRequest bindingsRequest) throws Exception {
        String apiPath = artemisPath +"/api/cis/v1/card/bindings";
        Map<String, String> path = new HashMap<>(2);

        path.put(agreement + "://", artemisPath + apiPath);

        String body=JSON.toJSONString(bindingsRequest);
        String json = ArtemisHttpUtil.doPostStringArtemis( path, body, null,  null, "application/json");
        JSONObject jsonObject = JSONObject.parseObject(json);
        log.info("返回的json：" + jsonObject);

        ResponseVo<CardBindingsVo> response = JSON.parseObject(
            json,
            new TypeReference<ResponseVo<CardBindingsVo>>() {}
        );
        return response;
    }


}
